package com.moge.anjian;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.GestureDescription;
import android.graphics.Path;
import android.util.Log;

import com.moge.anjian.service.MogeAccessibilityService;

public class MogeAccessibilityManager {

    private static MogeAccessibilityService mService;
    static AccessibilityService.GestureResultCallback callback;
    private static Thread mThread;

    public static void setService(MogeAccessibilityService service) {
        mService = service;
        callback =  new AccessibilityService.GestureResultCallback() {
            @Override
            public void onCompleted(GestureDescription gestureDescription) {
                super.onCompleted(gestureDescription);
                Log.e("dimoge", "手势完成");
            }

            @Override
            public void onCancelled(GestureDescription gestureDescription) {
                super.onCancelled(gestureDescription);
                Log.e("dimoge", "手势取消:");
            }
        };
    }

    public static MogeAccessibilityService getService () {

        return mService;
    }

    public static void performClick(float x, float y) {
        if (mService == null) {
            Log.e("dimoge", "服务为空, 不可用");
            return;
        }
        Path path = new Path();
        path.moveTo(x, y);
//        path.moveTo(clickX + 0F, clickY + 0F);
        GestureDescription.StrokeDescription strokeDescription = new GestureDescription.StrokeDescription(path, 0L, 1L);
        GestureDescription gestureDescription = new GestureDescription.Builder()
                .addStroke(strokeDescription)
                .build();
        mService.dispatchGesture(gestureDescription, null, null);
    }
}
